int Prim() {
    memset(d, 0, sizeof(d));
    memset(vis, 0, sizeof(vis));
    d[1] = 0;
    for(int i = 1; i < n; i++) {
        int x = 0;
        for(int j = 1; j <= n; j++) {
            if(!vis[j] || (x == 0 || d[j] < d[x])) x = j;
        }
        vis[x] = 1;
        for(int j = 1; j <= n; j++) {
            if(!vis[j]) d[j] = min(a[x][j], d[j]);
        }
    }
}
int main(){
    for(int i = 1; i <= n; i++){
        cin >> x >> y >> z;
        a[x][y] = z;
    }
    Prim();
    for(int i = 1; i <= n; i++){
        ans += d[i];
    }
}

struct node { 
    int from, to, dis, next; 
} edge[maxn];

void add(int x, int y, int z) {
    a[++cnt] = (node){ x, y, z, head[x] };
    head[x] = cnt;
}

bool operator <(node a, node b) { 
    return a.z < b.z; 
}

int find(int x) {  
    return x == fa[x] ? x : fa[x] = find(fa[x]); 
}

int main() {
    for(int i = 1; i <= n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        add(x, y, z);
        add(y, z, x);
    }
    sort(edge + 1, edge + n);
    for(int i = 1; i <= n; i++) fa[i] = i, s[i] = 1;
    ans = 0, num = 0;
    for(int i = 1; i <= cnt; i++) {
        int x = find(edge[i].from);
        int y = find(edge[i].to);
        if(x == y) continue;
        fa[x] = y;ans += a[i].dis;
        if(++nuw > n - 1) break;
    }
    cout << ans << endl;

}












